package mint.modules.symbol;

import java.util.Formatter;

import mint.modules.generator.FieldDeclarationNode;
import mint.modules.type.Type;

public class FieldSymbol extends Symbol {
	private Type type;
	private SymbolModifier modifier;
	private String modifierText;
	

	public FieldSymbol(FieldDeclarationNode node) {
		super(node.getName());
		type = node.getType();
		modifierText = node.getModifier();
		
		if (modifierText.equals("public"))
		{
			modifier = SymbolModifier.publicModifier;
		}
		else if (modifierText.equals("private"))
		{
			modifier = SymbolModifier.privateModifier;
		}
		else if (modifierText.equals("protected"))
		{
			modifier = SymbolModifier.protectedModifier;
		}
		else
			modifier = SymbolModifier.publicModifier;
	}
	
	private FieldSymbol(String name, String typeName) {
		super(name);
		type = Type.createObjectType(typeName);
		modifierText = "private";		
		modifier = SymbolModifier.privateModifier;		
	}
	
	public SymbolModifier getModifier()
	{
		return modifier;
	}
	
	public Type getType()
	{
		return type;
	}

	@Override
	public SymbolType getSymbolType() {
		return SymbolType.Field;
	}

	@Override
	public void print(Formatter output, int tabSize) {
		for (int i = 1; i <= tabSize; i++)
			output.format("\t");
		
		output.format("Field %s %s : ", modifierText, getName());
		type.print(output);
		output.format("\n");		
	}
	
	public static FieldSymbol createThisSymbol(String className)
	{
		FieldSymbol resp = new FieldSymbol("this", className);
		
		resp.modifier = SymbolModifier.protectedModifier;
		resp.modifierText = "protected";
		
		return resp; 
	}

}
